﻿using EnumsNET;
using Kinlo.Entitys;
using Kinlo.MESDocking;
using LiveChartsCore;
using LiveChartsCore.Defaults;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using MaterialDesignThemes.Wpf;
using NewLife.Data;
using SkiaSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using UIWindows.Commands;
using UIWindows.Domains;
using UIWindows.Enums;
using UIWindows.GlobalStatics;
using UIWindows.Models;
using UIWindows.Models.Homes;
using UIWindows.Services;
using UIWindows.Tools.Helper;
using UIWindows.ViewModels.Dialogs;
using UIWindows.Views;
using UIWindows.Views.Dialogs;
using XingLucifer.Devices;
using XingLucifer.IBase.Enums;
using static log4net.Appender.RollingFileAppender;
using static NPOI.HSSF.Util.HSSFColor;
using static System.Resources.ResXFileRef;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace UIWindows.ViewModels
{
    public class HomePageViewModel : UIWindows.Domains.ViewModelBase, XingLucifer.IBase.IViewStatus
    {
        #region 配置显示项
        public GridView ShortCircuitView { get; set; }
        /// <summary>
        /// 前称重表头数据模型
        /// </summary>
        public GridView BeforeWeightView { get; set; }
        /// <summary>
        /// 注液后称重表头数据模型
        /// </summary>
        public GridView AfterWeightView { get; set; }
        public GridView ProductionDataView { get; set; }
        #endregion
        #region 注液统计
        public IEnumerable<ISeries> NG_MultiLiquidSeries { get; set; }
        public IEnumerable<ISeries> LiquidInjection_PassingRateSeries { get; set; }
        public IEnumerable<ISeries> NG_LessLiquidSeries { get; set; }
        #endregion

        #region 后称重
        public IEnumerable<ISeries> LiquidInjectionNGSeries { get; set; }
        public IEnumerable<ISeries> LeakDetectionNGSeries { get; set; }
        public IEnumerable<ISeries> AfterWeighingPassingRateSeries { get; set; }
        #endregion

        public GlobalStatics.ParameterStatic Parameter { get; set; }
        public GlobalStatics.HomeStatic Home { get; set; }
        public GlobalStatics.TemporaryStatic Temporary { get; set; }
        public SystemConfigStatic _configStatic { get; set; }
        public DisplayItemsStatic _displayItems { get; set; }

        public HomePageViewModel(GlobalStatics.ParameterStatic parameter, GlobalStatics.HomeStatic home, GlobalStatics.TemporaryStatic temporaryStatic, SystemConfigStatic configStatic, DisplayItemsStatic displayItems)
        {
            Parameter = parameter;
            Home = home;
            ShortCircuitView = new GridView();
            ProductionDataView = new GridView();
            BeforeWeightView = new GridView();
            AfterWeightView = new GridView();
            #region 注液统计
            home.ChartData.OV_MultiLiquid = new ObservableValue();
            home.ChartData.OV_LessLiquid = new ObservableValue();
            home.ChartData.OV_LiquidInjection_PassingRate = new ObservableValue();
            NG_MultiLiquidSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(45)
            .WithBackgroundInnerRadius(32).WithLabelFormatter((point) => $"{point.PrimaryValue:####}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_MultiLiquid, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            NG_LessLiquidSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(45)
            .WithBackgroundInnerRadius(32).WithLabelFormatter((point) => $"{point.PrimaryValue:####}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_LessLiquid, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            LiquidInjection_PassingRateSeries = new GaugeBuilder().WithLabelsSize(18)
            .WithInnerRadius(60)
            .WithBackgroundInnerRadius(42).WithLabelFormatter((point) => $"{point.PrimaryValue:P2}")
            .WithBackground(new SolidColorPaint(new SKColor(100, 181, 246, 90)))
            .WithLabelsPosition(PolarLabelsPosition.ChartCenter)
            .AddValue(home.ChartData.OV_LiquidInjection_PassingRate, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192)))
            .BuildSeries();

            home.ChartData.OV_LiquidInjection_PassingRate.Value = 0;
            #endregion

            #region 后称重
            home.ChartData.OV_LiquidInjection = new ObservableValue();
            home.ChartData.OV_LeakDetection = new ObservableValue();
            home.ChartData.OV_AfterWeighingPassingRate = new ObservableValue();
            LiquidInjectionNGSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90)),
            }.AddValue(home.ChartData.OV_LiquidInjection, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();

            LeakDetectionNGSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90))
            }.AddValue(home.ChartData.OV_LeakDetection, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();

            AfterWeighingPassingRateSeries = new GaugeBuilder()
            {
                LabelsSize = 0,
                InnerRadius = 36,
                BackgroundInnerRadius = 25,
                Background = new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(100, 181, 246, 90))
            }.AddValue(home.ChartData.OV_AfterWeighingPassingRate, null, new LiveChartsCore.SkiaSharpView.Painting.SolidColorPaint(new SkiaSharp.SKColor(21, 101, 192))).BuildSeries();
            #endregion

            Temporary = temporaryStatic;
            _configStatic = configStatic;
            #region 前称重显示
            SetDisplayItemsBeforeWeight();
            SetShowBeforWeight();
            #endregion
            #region 后称重显示
            SetDisplayItemsAfterWeight();
            SetShowAfterWeight();
            #endregion

            #region 短路测试仪显示配置
            SetDisplayItemsShortCicute();
            SetShowShortCicute();
            #endregion
        }

      
        public DelegateCommand ClockOutline => new DelegateCommand(() =>
        {

        });

        private List<DisplayItemsModel> _displayItems_ShortCircuit;
        private List<DisplayItemsModel> _displayItems_BeforeWeight;
        private List<DisplayItemsModel> _displayItems_AfterWeight;


        public DelegateCommand WeighingConfigSave => new DelegateCommand(() =>
        {
            //var _deviceConfig = ObjectContainer.ResolveSingleton<DeviceConfigStatic>();
            //var weighingType = Parameter.WeighingConfig.ScaleType == TaskTypes.前称重 ? 1 : 2;
            //var plc = _deviceConfig.DeviceList.FirstOrDefault(t => t.DeviceType == DeviceTypes.CIP_Omron && t.ServiceName == "注液机");
            //if (plc == null || plc.Communication==null)
            //{
            //    //MessageBox.Show("请先运行！！！");
            //    //return;

            //    $"手动切换到{Parameter.WeighingConfig.ScaleType.ToString()}发送给PLC失败，设备未运行，PLC未连接！！！".RunLog(MessageLevelType.错误);
            //}
            //else
            //{
            //    OmronCIP omronCIP = plc.Communication as OmronCIP;
                
            //    //1前称 2后称
            //    if (omronCIP.WriteSingle((float)weighingType, "PC_Result_Scales.BeforeWeight[3].PLCData"))
            //    {
            //        $"手动切换到{Parameter.WeighingConfig.ScaleType.ToString()}发送给PLC信号{weighingType}成功".RunLog(MessageLevelType.成功);
            //    }
            //    else
            //    {
            //        $"手动切换到{Parameter.WeighingConfig.ScaleType.ToString()}发送给PLC信号{weighingType}失败".RunLog(MessageLevelType.错误);
            //    }
            //}
         
            Parameter.Save();
        });
        public DelegateCommand ZeroClearing => new DelegateCommand(() =>
        {
            if (MessageBox.Show($"确定要清空当前电池位置？当前电池位置:{Parameter.WeighingConfig.CurrentLocation}", "询问", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                Parameter.WeighingConfig.CurrentLocation = 0;
                Parameter.Save();
            }
        });
        public DelegateCommand Modify => new DelegateCommand(() =>
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                _ = MaterialDesignThemes.Wpf.DialogHost.Show(new Views.Dialogs.CustomDialog() { DataContext = new CustomDialogViewModel(Parameter) }, PopUpTypes.Global.ToString()).ConfigureAwait(false);
            });
        });

        //private string _selectedWeightMode="前称重";

        //public string SelectedWeightMode
        //{
        //    get { return _selectedWeightMode; }
        //    set
        //    {
        //        if (_selectedWeightMode != value)
        //        {
        //            if(value=="前称重")
        //            {
        //                Parameter.WeighingConfig.ScaleType = TaskTypes.前称重;
        //                Parameter.WeighingConfig.IsInitialized = true;
        //            }
        //            else
        //            {
        //                Parameter.WeighingConfig.ScaleType = TaskTypes.后称重;
        //                Parameter.WeighingConfig.IsInitialized = true;
        //            }
        //            _selectedWeightMode = value;
        //            OnPropertyChanged(nameof(SelectedWeightMode));
        //        }
        //    }
        //}



        public void Load()
        {
            if (_displayItems == null)
            {
                _displayItems = Domains.ObjectContainer.ResolveSingleton<DisplayItemsStatic>();
            }
            if (!_displayItems.IsHomeUpdate)
            {
                return;
            }
            _displayItems.IsHomeUpdate = false;
            ProductionDataView.Columns.Clear();
            List<DisplayItemsModel> list = new List<DisplayItemsModel>(_displayItems.WeighingDisplayItems);
            list.Sort((x, y) => x.CompareTo(y));
            foreach (var item in list)
            {
                if (item.IsDisplay)
                {
                    GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                    if (item.DataType == "结果")
                    {
                        FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                        border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                        border.SetBinding(Border.BackgroundProperty, new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            Converter = new Tools.Converter.ResultToColorConverter()
                        });

                        FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                        text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                        text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                        text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                        text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                        border.AppendChild(text);
                        var dataTemplate = new DataTemplate();
                        dataTemplate.VisualTree = border;
                        gvc.CellTemplate = dataTemplate;
                    }
                    else if (item.DataType == "浮点型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "F2"
                        };
                    else if (item.DataType == "时间型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "yyyy-MM-dd HH:mm:ss",
                            Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                        };
                    else
                        gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };
                    ProductionDataView.Columns.Add(gvc);
                }
            }
        }

        public void UnLoad()
        {

        }
        void SetDisplayItemsShortCicute()
        {
            var temp = new MessageShortCircuitModel();
            _displayItems_ShortCircuit = new List<DisplayItemsModel>()
            {
                new DisplayItemsModel(){
                    Index = 1,
                    DataType = "结果",
                    Description = "总结果",
                    Name = nameof(temp.Result) ,//这个双向绑定的属性
                    SqlName = "ALL",//用来区分是什么设备
                },
                new DisplayItemsModel(){
                    Index = 2,
                    Description = "位 置",
                    Name = "Location",
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 3,
                    Description = "条 码",
                    Name = "BarCode",
                    SqlName = "ALL",
                },
                 new DisplayItemsModel(){
                    Index = 4,
                    DataType = "结果",
                    Description = "开路结果",
                    Name = nameof(temp.开路结果) ,//这个双向绑定的属性
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 5,
                  DataType = "结果",
                  Description = "电阻测试结果",
                  Name = nameof(temp.电阻测试结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                 new DisplayItemsModel(){
                  Index = 6,
                  DataType = "结果",
                  Description = "电容测试结果",
                  Name = nameof(temp.电容测试结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 7,
                    DataType = "结果",
                    Description = "放电1结果",
                    Name = nameof(temp.放电1结果) ,//这个双向绑定的属性
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                   Index = 8,
                   DataType = "结果",
                   Description = "放电2结果",
                   Name = nameof(temp.放电2结果) ,//这个双向绑定的属性
                   SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                   Index = 9,
                   DataType = "结果",
                   Description = "VP结果",
                   Name = nameof(temp.VP结果) ,//这个双向绑定的属性
                   SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 10,
                  DataType = "结果",
                  Description = "跌落1结果",
                  Name = nameof(temp.跌落1结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 11,
                  DataType = "结果",
                  Description = "跌落2结果",
                  Name = nameof(temp.跌落2结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 12,
                  DataType = "结果",
                  Description = "跌落3结果",
                  Name = nameof(temp.跌落3结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 13,
                  DataType = "结果",
                  Description = "TL结果",
                  Name = nameof(temp.TL结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                  Index = 14,
                  DataType = "结果",
                  Description = "TH结果",
                  Name = nameof(temp.TH结果) ,//这个双向绑定的属性
                  SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 15,
                    DataType = "浮点型",
                    Description = "电阻值(MΩ)",
                    Name =nameof(temp.ElectrodesTestValue),
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 16,
                    Description = "电阻测试时间",
                    Name =nameof(temp.ElectrodesTestTime),
                    SqlName = "ALL",
                },
                new DisplayItemsModel(){
                    Index = 17,
                    DataType = "浮点型",
                    Description = "电容测试数据",
                    Name =nameof(temp.ElectrodesCapacitance),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 18,
                    Description = "跌落1",
                     Name =nameof(temp.跌落1),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 19,
                    Description = "跌落2",
                     Name =nameof(temp.跌落2),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                 new DisplayItemsModel(){
                    Index = 20,
                    Description = "跌落3",
                     Name =nameof(temp.跌落3),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 21,
                    Description = "VP电压(v)",
                    Name =nameof(temp.VP电压),
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },
                new DisplayItemsModel(){
                    Index = 22,
                    Description = "升压时间(ms)",
                    Name = "升压时间",
                    SqlName = DeviceTypes.RJ6902R_ShortCircuit.ToString(),
                },



            };

        }
        void SetShowShortCicute()
        {

            foreach (var item in _displayItems_ShortCircuit)
            {
                if (item.SqlName == _configStatic.SCM.ShortCircuit.ToString() || item.SqlName == "ALL")
                {
                    GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                    if (item.DataType == "结果")
                    {
                        FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                        border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                        border.SetBinding(Border.BackgroundProperty, new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            Converter = new Tools.Converter.ResultToColorConverter()
                        });

                        FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                        text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                        text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                        text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                        text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                        border.AppendChild(text);
                        var dataTemplate = new DataTemplate();
                        dataTemplate.VisualTree = border;
                        gvc.CellTemplate = dataTemplate;
                    }
                    else if (item.DataType == "浮点型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "F2"
                        };
                    else if (item.DataType == "时间型")
                        gvc.DisplayMemberBinding = new Binding
                        {
                            Path = new System.Windows.PropertyPath(item.Name),
                            StringFormat = "yyyy-MM-dd HH:mm:ss",
                            Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                        };
                    else
                        gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                    ShortCircuitView.Columns.Add(gvc);
                }
            }
        }
        void SetDisplayItemsBeforeWeight()
        {
            var temp = new MessageBeforeWeighingModel();
            if (_configStatic.SCM.MainDeviceType == MainDeviceTypeEnum.一次注液)
            {
                _displayItems_BeforeWeight = new List<DisplayItemsModel>
                 {
                         new DisplayItemsModel()
                         {
                             Index = 1,
                             DataType = "结果",
                             Description = "结 果",
                             Name =nameof(temp.Result),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 2,
                             Description = "条 码",
                             Name =nameof(temp.BarCode),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 3,
                             //DataType = "时间型",
                             Description = "前称时间",
                             Name =nameof(temp.Time),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 4,
                             DataType = "浮点型",
                             Description = "前称重量",
                             Name =nameof(temp.FormerWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 5,
                             Description = "前称重位置",
                             Name =nameof(temp.LocationFormerWeighing),//这个双向绑定的属性 
                         },
                 };
            }
            else
            {
                _displayItems_BeforeWeight = new List<DisplayItemsModel>
                 {
                         new DisplayItemsModel()
                         {
                             Index = 1,
                             DataType = "结果",
                             Description = "结 果",
                             Name =nameof(temp.Result),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 2,
                             Description = "条 码",
                             Name =nameof(temp.BarCode),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 3,
                            // DataType = "时间型",
                             Description = "前称时间",
                             Name =nameof(temp.Time),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 4,
                              DataType = "浮点型",
                             Description = "前称重量",
                             Name =nameof(temp.FormerWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 5,
                             Description = "前称重位置",
                             Name =nameof(temp.LocationFormerWeighing),//这个双向绑定的属性 
                         },
                           new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "目标注液量",
                             Name =nameof(temp.TargetInjectionVolume),//这个双向绑定的属性 
                         },
                            new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "化成失液量",
                             Name =nameof(temp.LossAfterFormation),//这个双向绑定的属性 
                         },
                            new DisplayItemsModel()
                         {
                             Index = 7,
                              DataType = "浮点型",
                             Description = "电池干重",
                             Name =nameof(temp.NetWeight),//这个双向绑定的属性 
                         },
                             new DisplayItemsModel()
                         {
                             Index = 8,
                              DataType = "浮点型",
                             Description = "一注后称重",
                             Name =nameof(temp.OneAfterWeighing),//这个双向绑定的属性 
                         },
                 };
            }
        }
        void SetDisplayItemsAfterWeight()
        {
            var temp = new MessageAfterWeighingModel();
            _displayItems_AfterWeight = new List<DisplayItemsModel>
                 {
                         new DisplayItemsModel()
                         {
                             Index = 1,
                             DataType = "结果",
                             Description = "总结果",
                             Name =nameof(temp.Result),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 2,
                             Description = "条 码",
                             Name =nameof(temp.BarCode),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 3,
                             Description = "后称重位置",
                             Name =nameof(temp.LocationAfterWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 4,
                             Description = "前称重位置",
                             Name =nameof(temp.LocationFormerWeighing),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 5,
                             DataType = "浮点型",
                             Description = "前称重量",
                             Name =nameof(temp.FormerWeighing),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 6,
                             DataType = "浮点型",
                             Description = "后称重量",
                             Name =nameof(temp.AfterWeighing),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 7,
                             DataType = "浮点型",
                             Description = "目标注液量",
                             Name =nameof(temp.TargetInjectionVolume),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 8,
                             DataType = "浮点型",
                             Description = "实际注液量",
                             Name =nameof(temp.ActualInjectionVolume),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 9,
                             DataType = "浮点型",
                             Description = "注液量偏差值",
                             Name =nameof(temp.InjectionVolumeDeviationValue),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 10,
                             DataType = "浮点型",
                             Description = "保液量",
                             Name =nameof(temp.ActualTotalInjectionVolume),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 11,
                             Description = "前称重范围",
                             Name =nameof(temp.RangeForeweigh),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 12,
                             Description = "后称重范围",
                             Name =nameof(temp.RangeAfterWeighing),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 14,
                             Description = "保液量范围",
                             Name =nameof(temp.RangeFluidRate),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 15,
                             DataType = "结果",
                             Description = "测漏结果",
                             Name =nameof(temp.LeakResult),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 16,
                             DataType = "结果",
                             Description = "前称结果",
                             Name =nameof(temp.ResultFormerWeighing),//这个双向绑定的属性 
                         },
                          new DisplayItemsModel()
                         {
                             Index = 17,
                             DataType = "结果",
                             Description = "后称结果",
                             Name =nameof(temp.ResultAfterWeighing),//这个双向绑定的属性 
                         },

                         new DisplayItemsModel()
                         {
                             Index = 18,
                             //DataType = "时间型",
                             Description = "前称时间",
                             Name =nameof(temp.TimeFormerWeighing),//这个双向绑定的属性 
                         },
                         new DisplayItemsModel()
                         {
                             Index = 19,
                             //DataType = "时间型",
                             Description = "后称时间",
                             Name =nameof(temp.TimeAfterWeighing),//这个双向绑定的属性 
                         },
                        
                         
                 };
        }

        public DelegateCommand ClickMe => new DelegateCommand(() =>
        {
            MySqlHelper mySqlHelper = new MySqlHelper(Parameter.MESParameter.OthenDatabaseurl);
            var oneData = mySqlHelper.GetBatteryByCode("Empty83564123456789024720");
            if (oneData.status)
            {
                var NetWeight = oneData.netWeight;
                var OneAfterWeighing = oneData.outputWeight;
            }
        });

        void SetShowBeforWeight()
        {
            foreach (var item in _displayItems_BeforeWeight)
            {
                GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                if (item.DataType == "结果")
                {
                    FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                    border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                    border.SetBinding(Border.BackgroundProperty, new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        Converter = new Tools.Converter.ResultToColorConverter()
                    });

                    FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                    text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                    text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                    text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                    text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                    border.AppendChild(text);
                    var dataTemplate = new DataTemplate();
                    dataTemplate.VisualTree = border;
                    gvc.CellTemplate = dataTemplate;
                }
                else if (item.DataType == "浮点型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "F2"
                    };
                else if (item.DataType == "时间型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "yyyy-MM-dd HH:mm:ss",
                        Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                    };
                else
                    gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                BeforeWeightView.Columns.Add(gvc);
            }


        }
        
        void SetShowAfterWeight()
        {
            foreach (var item in _displayItems_AfterWeight)
            {
                GridViewColumn gvc = new GridViewColumn { Header = item.Description };
                if (item.DataType == "结果")
                {
                    FrameworkElementFactory border = new FrameworkElementFactory(typeof(Border));
                    border.SetValue(Border.CornerRadiusProperty, new CornerRadius(3));
                    border.SetBinding(Border.BackgroundProperty, new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        Converter = new Tools.Converter.ResultToColorConverter()
                    });

                    FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBlock));
                    text.SetValue(TextBlock.MarginProperty, new Thickness(5, 3, 5, 3));
                    text.SetValue(TextBlock.ForegroundProperty, new SolidColorBrush(Colors.White));
                    text.SetValue(TextBlock.HorizontalAlignmentProperty, HorizontalAlignment.Center);
                    text.SetBinding(TextBlock.TextProperty, new Binding { Path = new System.Windows.PropertyPath(item.Name) });

                    border.AppendChild(text);
                    var dataTemplate = new DataTemplate();
                    dataTemplate.VisualTree = border;
                    gvc.CellTemplate = dataTemplate;
                }
                else if (item.DataType == "浮点型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "F2"
                    };
                else if (item.DataType == "时间型")
                    gvc.DisplayMemberBinding = new Binding
                    {
                        Path = new System.Windows.PropertyPath(item.Name),
                        StringFormat = "yyyy-MM-dd HH:mm:ss",
                        Converter = new Tools.Converter.TimeStampToDateTimeStringConverter()
                    };
                else
                    gvc.DisplayMemberBinding = new Binding { Path = new System.Windows.PropertyPath(item.Name) };

                AfterWeightView.Columns.Add(gvc);
            }


        }

        public DelegateCommand TestCMD => new DelegateCommand(() =>
        {
            int b = 239;
            double c = (double)b /240;
            double a = Math.Round(c, 4, MidpointRounding.ToNegativeInfinity) ;
            a = a * 100;
            $"{a}".MessageDialogs(MessageLevelType.信息, false, Enums.PopUpTypes.Global);
        });
    }

   
}
